- title "#{@backlog.name} – #{@backlog.company.present? ? @backlog.company.name : @backlog.account.name}"
- content_for :head do
  = javascript_include_tag 'backlog'
  = stylesheet_link_tag 'backlog'
  - if is_example_backlog?
    = stylesheet_link_tag 'backlog_walkthrough', :media => 'all'
  = javascript_include_tag '//cdn.ably.io/lib/ably.min.js'

- content_for :global_nav_left do
  .logo
    = link_to root_path do
      .icon
    =link_to raw('← Back to dashboard'), account_path(@backlog.account)

- if @backlog.is_snapshot?
  .not-editable-backlog-notice.snapshot
    .message
      = "You are viewing a read only snapshot"
      = link_to '← Back', account_backlog_path(@backlog.account, @backlog.backlog_root)
- elsif @backlog.archived?
  .not-editable-backlog-notice
    .message
      You are viewing a non-editable archive

-# Snapshot container appears when user clicks on Snapshots
.snapshot-menu-container
  .selector
    .title
      =label_tag 'menu_snapshot_select', 'Select a snapshot to view:'
    .select
      != render :partial => 'snapshot_select', :locals => { :truncate_at => 35, :select_id=> 'menu_snapshot_select' }
  - if can?(:full)
    .button-holder
      %a#new-snapshot.button{:href => create_snapshot_account_backlog_path(@backlog.account, @backlog.all_snapshot_master || @backlog)} Create new snapshot
    .description
      Creates an exact copy of the current backlog for later reference
  .button-holder
    %a#compare-snapshot.button{:href => '#compare-snapshots'} Compare snapshots
  .description
    View changes between the current version and any historical snapshots

#filter-container
  %form
    %div
      = check_box_tag 'filter_completed'
      = label_tag 'filter_completed', 'Hide accepted stories'
    %div
      = check_box_tag 'filter_assigned'
      = label_tag 'filter_assigned', 'Hide stories assigned to sprints'

#backlog-data-area
  .actions
    .filter
      %a#filter-menu{ :vtip => 'Filter stories from this view' } Filter
    .divider
    .snapshot
      %a#snapshot-menu Snapshots
    .divider
    - if @backlog.is_snapshot?
      = link_to "Export", download_snapshot_account_backlog_path(@backlog.account, @backlog.backlog_root.id, @backlog.id, @backlog.name.parameterize, :format => :xls), :title => 'Download Snapshot in Excel format', :class => 'vtip'
      .divider
      = link_to "Print", download_snapshot_account_backlog_path(@backlog.account, @backlog.backlog_root.id, @backlog.id, @backlog.name.parameterize, :format => :pdf), :title => 'Print user story cards', :class => 'vtip', :id => 'print'
    - else
      = link_to "Export", download_account_backlog_path(@backlog.account, @backlog, @backlog.name.parameterize, :format => :xls), :title => 'Download Backlog in Excel format', :class => 'vtip'
      .divider
      = link_to "Print", download_account_backlog_path(@backlog.account, @backlog, @backlog.name.parameterize, :format => :pdf), :title => 'Print user story cards', :class => 'vtip', :id => 'print'
    .divider
    - if @backlog.is_snapshot?
      = link_to 'Settings', edit_account_backlog_path(@backlog.account, @backlog)
    - else
      = link_to 'Settings', edit_account_backlog_path(@backlog.account, @backlog), :id => 'backlog-settings-link'
  .name-company-container
    %h2.name{ :class => @backlog.editable? ? '' : 'locked'}
      - if @backlog.backlog_root.blank?
        = truncate(@backlog.name, :length => 40)
      - else
        = truncate(@backlog.backlog_root.name, :length => 40)
    -if @backlog.company
      %h3.company= truncate(@backlog.company.name, :length => 25)
    -else
      %h3.company= truncate(@backlog.account.name, :length => 25)
  .backlog-stats
    %div.title Backlog total:
    %div.output &nbsp;

#backlog-tabs
  #add-sprint.vtip{ :title => 'Create sprint' }
    %a.ui-icon.ui-icon-plusthick
  #protect-beneath-tabs
  %ul.infinite-tabs

- if @backlog.backlog_root.present?
  #viewing-snapshot-container
    .title
      =label_tag 'popup_snapshot_select', 'Viewing snapshot:'
    .selector
      != render :partial => 'snapshot_select', :locals => { :truncate_at => 45, :select_id => 'popup_snapshot_select' }

#presence-notifier
#backlog-container
  .filter-notifier
    You are viewing a filtered view of this backlog.
    %a{ :href => '#remove-filter', :id => 'remove-filter' } Remove filter »
  = render :partial => 'themes_container', :locals => { :backlog => @backlog }
  .filter-notifier
    You are viewing a filtered view of this backlog.
    %a{ :href => '#remove-filter', :id => 'remove-filter' } Remove filter »
#sprints-container.contracted-unassigned-stories
#sprints-help-container
#stats-container

- if @backlog.not_ready?
  #backlog-snapshot-not-ready
    This #{@backlog.is_snapshot? ? 'snapshot' : 'backlog'} is still being prepared.
    %br
    This page will automatically refresh as soon as your #{@backlog.is_snapshot? ? 'snapshot' : 'backlog'} is ready.
  :javascript
    $(document).ready(function() {
      setTimeout(function() {
        window.location.reload();
      }, 5000);
    });
- else
  #loading-new-snapshot
    %div.background.ui-widget-overlay
    %div.loading
      %span.progress-icon
      %p
        Loading, please wait...

:javascript
  $(document).ready(function() {
    if ($.datepicker.regional['#{current_locale_code}']) {
      $.datepicker.setDefaults($.datepicker.regional['#{current_locale_code}']);
    }

    var router = new App.Routers.Backlog();

    App.Collections.SprintStoryStatuses = new SprintStoryStatusesCollection(#{embedded_json_safe sprint_story_statuses_json});
    App.Collections.Backlogs = new BacklogsCollection(false, { account_id: #{@backlog.account.id} });
    var thisBacklog = new Backlog(#{embedded_json_safe backlog_json(@backlog)});
    App.Collections.Backlogs.add(thisBacklog);

    var backlogData = new App.Views.BacklogDataArea.Show({ model: thisBacklog, router: router, el: $('#backlog-data-area') });
    backlogData.render();
    var sprintTabs = new App.Views.SprintTabs.Index({ collection: thisBacklog.Sprints(), el: $('#backlog-tabs'), router: router });
    sprintTabs.render();
    var presence = new App.Views.BacklogPresence.Show({
      model: thisBacklog,
      user: {
        name: '#{escape_javascript current_user.name}',
        accounts: [#{current_user.accounts.map { |a| "'#{ escape_javascript a.name }'" }.join(",") }],
        id: #{current_user.id}
      },
      el: $('#presence-notifier')
    });
    presence.render();

    router.setTabsReference(sprintTabs);
    #{ @backlog.not_ready? ? '' : 'Backbone.history.start();' }

    // validation only needed for tabs, so load after page is ready
    $('head').append('#{j(javascript_include_tag 'validation', 'backlog_async')}');
  });
  #{render :partial => 'i18n', :formats => :js}

- if is_example_backlog?
  = javascript_include_tag 'backlog_walkthrough'
